//
//  IGCommentHuaDanCell.m
//  jingdongfang
//
//  Created by BOE on 2018/5/17.
//  Copyright © 2018年 BOE-SBG-CTO. All rights reserved.
//

#import "IGCommentHuaDanCell.h"

@interface IGCommentHuaDanCell()

@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *huadanLabel;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIImageView *headerImgView;
@property (nonatomic, strong) UILabel *nameLabel;

@end
@implementation IGCommentHuaDanCell

+ (IGCommentHuaDanCell *)cellWithTableView:(UITableView *)tableView
{
    IGCommentHuaDanCell *cell = [tableView dequeueReusableCellWithIdentifier:@"kIGCommentHuaDanCell"];
    if (!cell) {
        cell = [[IGCommentHuaDanCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"kIGCommentHuaDanCell"];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createUI];
    }
    return self;
}

- (void)createUI {
    _imgView = [[UIImageView alloc] init];
    [self.contentView addSubview:_imgView];
    [_imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(12);
        make.width.height.mas_equalTo(100);
    }];
    
    _huadanLabel = [UILabel new];
    [self.contentView addSubview:_huadanLabel];
    _huadanLabel.textAlignment = NSTextAlignmentCenter;
    _huadanLabel.font = [UIFont font12];
    _huadanLabel.textColor = [UIColor appColor];
    _huadanLabel.layer.masksToBounds = YES;
    _huadanLabel.layer.cornerRadius = 8;
    _huadanLabel.layer.borderWidth = 1;
    _huadanLabel.layer.backgroundColor = [UIColor appColor].CGColor;
    _huadanLabel.text = @"画单";
    [_huadanLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(27);
        make.left.mas_equalTo(_imgView.mas_right).mas_offset(18);
        make.width.mas_equalTo(30);
        make.height.mas_equalTo(18);
    }];
    
    _titleLabel = [UILabel new];
    [self.contentView addSubview:_titleLabel];
    _titleLabel.textAlignment = NSTextAlignmentLeft;
    _titleLabel.font = [UIFont font16];
    _titleLabel.textColor = [UIColor c4Color];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(27);
        make.left.mas_equalTo(_huadanLabel.mas_right).mas_offset(4);
        make.right.mas_equalTo(-10);
        make.height.mas_equalTo(18);
    }];
    
    _headerImgView = [UIImageView new];
    [self.contentView addSubview:_headerImgView];
    [_headerImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_imgView.mas_right).mas_offset(18);
        make.top.mas_equalTo(_titleLabel.mas_bottom).mas_offset(10);
        make.width.height.mas_equalTo(24);
    }];
    
    _nameLabel = [UILabel new];
    [self.contentView addSubview:_nameLabel];
    _nameLabel.textAlignment = NSTextAlignmentLeft;
    _nameLabel.font = [UIFont font14];
    _nameLabel.textColor = [UIColor c4Color];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_headerImgView.mas_right).mas_offset(8);
        make.centerY.mas_equalTo(_headerImgView.mas_centerY);
        make.height.mas_equalTo(12);
        make.right.mas_equalTo(-10);
    }];
}

- (void)setModel:(IGWorkDetailModel *)model {
    _model = model;
    
    if ([model.plates intValue] == 2) {
        [_imgView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.bottom.mas_equalTo(-50);
            make.width.mas_equalTo(211);
            make.centerX.mas_equalTo(self.mas_centerX);
        }];
    }
    [_imgView sd_setImageWithURL:[NSURL URLWithString:model.worksImage]];
    _nameLabel.text = model.worksName;
//    _authorLabel.text = model.worksAthena;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
